/* Doesnt' work. Why? */
//AjaxLab.Engine.Plugins.BaseCommands.callBaseMethod(this, 'registerCommands',[customCommands]);

/*
		Will it be better to use delegate and have users define their own method instead? lik
		this.registerCommandProcess(custoCommand, commandCallBack, commandCallBackContext);
		
		CMDUtil.js is avaiable for plug in classes to use. - instance.Console
*/
	
Type.registerNamespace("AjaxLab.Engine.Plugins");
AjaxLab.Engine.Plugins.BaseCommands= function()
{
	var customCommands = "CLEAR|CD|DEBUG|ENABLE|DISABLE|OpenUrl";
	
	var instance = this;
	AjaxLab.Engine.Plugins.BaseCommands.initializeBase(this);
	this.registerCommands(customCommands);
	
	/* Implement the Plug In here */
	this.win = null;
	
	this.processCommands = function(inputtext) {
		
		instance.Log4J.setRootLevel(instance.Log4J.LevelTypes.Debug);
		instance.Log4J.Debug("Input text is :"+inputtext);
		instance.Log4J.Info("Input text is :"+inputtext);
		instance.Log4J.Warn("Input text is :"+inputtext);
		instance.Log4J.Error("Input text is :"+inputtext);
		instance.Log4J.Fatal("Input text is :"+inputtext);
		
        var command     = inputtext.split(" ");
					
		instance.Log4J.Fatal("command is :"+command[0]);
		
			if(command[0].toUpperCase() == "OPENURL" || command[0].toUpperCase() == "BROWSE" )
			{
				var url = "http://www.limingxu.com";
				if(command[1]==null){
					instance.Log4J.Debug("no url specified, will get root value");
					url = instance.Console.getRoot();
					instance.Log4J.Debug("url is :"+url);
				}
				else{
					instance.Log4J.Debug("url is :"+url);
					url = command[1];
					instance.Log4J.Debug("url is :"+url);
				}
				if(!instance.win)
				{
					instance.Log4J.Debug("create url window "+url);
					instance.win = new Window(
									 "BrowseWindow"+new Date(), 
									 {
										 className: "dialog", 
										 title: url, 
										 top:70, left:100, width:600, height:500, 
										 resizable: true, 
										 url: url, 
										 showEffectOptions: {duration:3}
										}
									)
				}
							instance.win.show(); 
							instance.win.toFront();
							instance.Console.newPrompt();
			}
			else if(command[0].toUpperCase() == "CLEAR" || command[0].toUpperCase() == "CLS")
			{
							instance.Log4J.Debug("Clear detected");
							instance.Log4J.Debug("Command[1] is :"+command[1]);
							if(command[1]=="")
							{
								instance.Log4J.Debug("it's empty string");
							}
							//ToDo: input text might have trialing line feed command[1] might not work. 
							//need to check. Should be implemented in the base class
							if(command[1]==null)
							{
								instance.Console.clearScreen();
							}
							else if(command[1].toUpperCase() == "DEBUG")
							{
								instance.Log4J.Debug("Clear Debug detected");
								instance.Console.emptyDebugZone();
							}
							
			}
			else if(command[0].toUpperCase()=="ENABLE")
			{
							instance.Log4J.Debug("Enable detected");
							if(command[1].toUpperCase() == "AUTOCOMPLETE")
							{
								instance.Log4J.Debug("auto complete on");

								instance.enableAutoComplete = true;
								instance.Console.newPrompt();
							}
							else if(command[1].toUpperCase() == "DEBUG")
							{
								instance.Log4J.setIsDebug(true);
								instance.Console.newPrompt();
								instance.Log4J.Debug("Debug Enabled");
							}
			}
			else if(command[0].toUpperCase()=="DISABLE")
			{
							instance.Log4J.Debug("Disaable detected");
							if(command[1].toUpperCase() == "AUTOCOMPLETE")
							{
								instance.Log4J.Debug("auto complete off");
								instance.enableAutoComplete = false;
								var div = document.getElementById("myDiv");							
								div.style.display="none";
								instance.Console.newPrompt();
							}
							else if(command[1].toUpperCase() == "DEBUG")
							{
								instance.Log4J.Debug("About to disable debug");
								instance.Log4J.setIsDebug(false);
								if(command[2]!=null && command[2].toUpperCase() =="CLEAR")
								{
									instance.Console.emptyDebugZone();
								}
								else{
									instance.Console.newPrompt();
								}
							}
			}
			else if(command[0].toUpperCase()=="CD")
			{
							if(command[1]!="")
							{
								instance.Console.cd(command[1]);
							}
			}
			else{
							instance.Log4J.Debug("No Command Found");
							instance.Console.printToConsole(inputtext+" is not recognized as an internal or external command");
			}
    }
}
AjaxLab.Engine.Plugins.BaseCommands.registerClass('AjaxLab.Engine.Plugins.BaseCommands', AjaxLab.Engine.Abstract.Commands);




